package com.gimi.cloud.jimi.manage.service.user.impl;


import com.gimi.cloud.jimi.common.jwt.Jwt;
import com.gimi.cloud.jimi.dao.dao.sys.SysConfigDao;
import com.gimi.cloud.jimi.manage.service.user.ApiUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by shazhiwei on 2017/10/31.
 */
@Service
public class ApiUserServiceImpl implements ApiUserService {
    private final SysConfigDao payConfigMapper;

    @Autowired
    public ApiUserServiceImpl(SysConfigDao payConfigMapper){
        this.payConfigMapper = payConfigMapper;
    }

    @Override
    public String getToken() {
        Map<String, Object> payload = new HashMap<String, Object>();
        Date date = new Date();
        payload.put("uid", "userId");//用户id
        payload.put("iat", date.getTime());//生成时间
        payload.put("ext", date.getTime() + 1000 * 60 * 60 * 24);//过期时间24小时
        payload.put("version", "1.0");
        String token = Jwt.createToken(payload,null);
        return token;
    }

    @Override
    public String getTokenSecret() {
        return payConfigMapper.getValueByKey("jwt_token_secret");
    }
}
